import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import static java.util.Collections.shuffle;

public class CardDemo extends Card {

    //花色数组
    public static final String[] suit={"♠", "♥", "♣", "♦"};
    //颜色数组
    public static final String[] colour={"红色","黑色"};
    private static List<Card> buyDeck() {
        List<Card> deck = new ArrayList<>(52);
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = CardDemo.suit[i];
                String colout = CardDemo.colour[(i + 1) % 2];
                int rank = j;
                Card card = new Card();
                card.colour = colout;
                card.suit = suit;
                card.rank = rank;
                deck.add(card);
            }
        }
        return deck;
    }

    public static void swap(List<Card> deck,int x,int y) {
        Card p= deck.get(x);
        deck.set(x,deck.get(y));
        deck.set(y,p);
    }
    public static void myshuffle(List<Card> deck) {

        //洗牌
        Random random = new Random(20190905);
        for (int i = deck.size()-1; i >0 ; i--) {
            int n=random.nextInt(i);
            swap(deck,i,n);
        }

    }
   public static List<List<Card>> playdeck(List<Card> deck) {
        List<List<Card>> deck4=new ArrayList<>();
        deck4.add(new ArrayList<>());
        deck4.add(new ArrayList<>());
        deck4.add(new ArrayList<>());
       for (int i = 0; i < 3; i++) {
           for (int j = 0; j < 5; j++) {
               deck4.get(i).add(deck.remove(0));
           }
       }
        return deck4;
    }

    public static void main(String[] args) {
        //买牌
        List<Card>deck= CardDemo.buyDeck();
        System.out.println(deck);
        //洗牌
        myshuffle(deck);
        System.out.println(deck);
        //玩牌，三人轮流一人五张
       List<List<Card>> p= playdeck(deck);
        System.out.println(p.get(0));
        System.out.println(p.get(1));
        System.out.println(p.get(2));
        //剩下的牌个数
        System.out.println(deck.size());
        //剩下的牌是什么
        System.out.println(deck);
    }
}
